home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Megahits 5
/
Megahits 5 (1994)(GTI - Rhein-Main-Soft)(DE)(Disc 2 of 2)[!].iso
/
archive
/
print
/
dvi2pcl.lha
/
sortfonts.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-11-25
|
2KB
|
80 lines
/*
* Sorts order of fonts used in the dvi-file and not stored permanently in
* the printers memory in respect to font usage. Therefore a rating value
* is calculated for each font from their character usage in the document.
* The fonts are ordered in `fontlist' in order of their rating value
* `usage'. The function returns the number of different fonts used, but
* not stored permanently. As a side effect, for each font the first and
* last character, used in the document ist stored in font->bc and font->ec
* resp., to avoid unnecessary searching later on.
*/
#include "globals.h"
int sortfonts(fontlist)
int fontlist[];
{
int f;
int i;
int t;
int store_all;
int fontnum = 0;
long total;
long different;
long tt;
long usage[MAXFONTS];
charfmt *u;
charfmt *cbase;
/* Determine rating value for each font used but not perm loaded */
for (f = 0 ; f < MAXFONTS ; f++)
if ((font = fontptr[f]) && (font->down < 0)) {
cbase = font->chr;
total = different = 0;
font->bc = 256;
font->ec = -1;
for(i = 0 ; i < 256 ; i++)
if((cbase + i)->use_count)
{
font->bc = i;
break;
} /* First char used */
for(i = 255 ; i >= font->bc ; i--)
if((cbase + i)->use_count) {
font->ec = i;
break;
} /* Last char used */
for(i = font->bc ; i <= font->ec ; i++) {
u = cbase + i;
if(u->use_count) {
different++;
total += u->use_count;
} /* Different used chars */
} /* and total usage */
fontlist[fontnum] = f;
/* Calculate rating */
if(different)
usage[fontnum++] =
(256*(total - different))/different;
else
usage[fontnum++] = 0;
}
/* Now sort used fonts in order of the usage rating values */
for(f = fontnum - 1 ; f > 0 ; f--)
for(i = 0 ; i < f ; i++)
if(usage[i] < usage[f]) {
tt = usage[i];
usage[i] = usage[f];
usage[f] = tt;
t = fontlist[i];
fontlist[i] = fontlist[f];
fontlist[f] = t;
}
/* Return the number of different fonts not permanently loaded */
return(fontnum);
}